import { createRouter, createWebHistory } from "vue-router";
import store from "@/store"; // 引入 Vuex store

// 路由配置
const routes = [
  {
    path: "/",
    name: "Layout",
    component: () => import("@/layouts/Layout.vue"), // App 主组件
    children: [
      // 任务管理
      {
        path: "", // 默认子路由
        name: "TaskManagement",
        component: () => import("@/views/TaskManagement/TaskManagement.vue"),
        meta: { navId: "TaskManagement", topMenu: "/", title: "任务管理" }, // 需要认证
      },
      {
        path: "TaskDetails",
        name: "TaskDetails",
        component: () => import("@/views/TaskManagement/TaskDetails.vue"),
        meta: { navId: "TaskManagement", topMenu: "/", title: "任务详情" }, // 需要认证
      },
      // 角色制作
      {
        path: "roleMake",
        name: "RoleMake",
        component: () => import("@/views/roleMaking/index.vue"),
        meta: { navId: "roleMake", topMenu: "/roleMake", title: "角色制作" },
      },
      // 情景制作
      {
        path: "sceneMake",
        name: "SceneMake",
        redirect: "/sceneMake/index",
        meta: { navId: "sceneMake", topMenu: "/sceneMake", title: "情景制作" },
        children: [
          {
            path: "index",
            name: "SceneMakeIndex",
            component: () => import("@/views/sceneMaking/index.vue"),
            meta: { navId: "sceneMake", topMenu: "/sceneMake", title: "情景制作" },
          },
          {
            path: "sceneMakeDetails",
            name: "SceneMakeDetails",
            component: () => import("@/views/sceneMaking/sceneMakeDetails.vue"),
            meta: { navId: "sceneMake", topMenu: "/sceneMake", title: "情景制作" },
          },
          {
            path: "moreRoles",
            name: "MoreRoles",
            component: () => import("@/views/sceneMaking/MoreRoles.vue"),
            meta: { navId: "sceneMake", topMenu: "/sceneMake", title: "情景制作" },
          },
        ],
      },
      // 机构管理
      {
        path: "institutionManage",
        name: "InstitutionManage",
        redirect: "/institutionManage/index",
        meta: { navId: "institutionManage", topMenu: "/institutionManage", title: "机构管理" },
        children: [
          {
            path: "index",
            name: "InstitutionManageIndex",
            component: () => import("@/views/institutionManage/index.vue"),
            meta: { navId: "institutionManage", topMenu: "/institutionManage", title: "机构管理" },
          },
          {
            path: "groupInfo",
            name: "GroupInfo",
            component: () => import("@/views/institutionManage/groupInfo.vue"),
            meta: { navId: "institutionManage", topMenu: "/institutionManage", title: "小组管理" },
          },
          {
            path: "groupMember",
            name: "GroupMember",
            component: () => import("@/views/institutionManage/groupMember.vue"),
            meta: { navId: "institutionManage", topMenu: "/institutionManage", title: "小组成员" },
          },
        ],
      },
      // 人员管理
      {
        path: "personManage",
        name: "PersonManage",
        component: () => import("@/views/personManage/index.vue"),
        meta: { navId: "personManage", topMenu: "/personManage", title: "人员管理" },
      },
      {
        path: "personManage/trainingUser",
        name: "TrainingUser",
        component: () => import("@/views/personManage/trainingUser.vue"),
        meta: { navId: "personManage", topMenu: "/personManage", title: "培训用户" },
      },
      {
        path: "zonghe", // 综合能力评定
        name: "zonghe",
        meta: {
          navId: "zonghe-main",
          requiresAuth: true,
          title: "综合能力评定",
        }, // 需要认证
        children: [
          /*==========综合能力评定=============*/
          {
            path: "zongheping",
            name: "zongheping",
            component: () => import("@/views/ZongHe/ZongHePing.vue"),
            meta: { title: "综合能力评定", navId: "zonghe-ping" },
          },
          /*==========毕业=============*/
          {
            path: "zonghebiye",
            name: "zonghebiye",
            component: () => import("@/views/ZongHe/ZongHeBiye.vue"),
            meta: { title: "目标/要求设定", navId: "zonghe-biye" },
            children: [
              {
                path: "",
                name: "biye1",
                component: () => import("@/views/ZongHe/Biye1.vue"),
                meta: { title: "毕业目标设定", navId: "zonghe-biye" },
              },
              {
                path: "biye2",
                name: "biye2",
                component: () => import("@/views/ZongHe/Biye2.vue"),
                meta: { title: "毕业要求设定", navId: "zonghe-biye" },
              },
              {
                path: "biye3",
                name: "biye3",
                component: () => import("@/views/ZongHe/Biye3.vue"),
                meta: { title: "毕业目标-毕业要求矩阵", navId: "zonghe-biye" },
              },
              {
                path: "biye4",
                name: "biye4",
                component: () => import("@/views/ZongHe/Biye4.vue"),
                meta: { title: "毕业要求-课程体系矩阵", navId: "zonghe-biye" },
              },
            ],
          },
          /*==========达成度=============*/
          {
            path: "zonghelist",
            name: "zonghelist",
            component: () => import("@/views/ZongHe/ZongHeList.vue"),
            meta: { title: "达成度列表", navId: "zonghe-list" },
          },
          {
            path: "zonghedetails/:id",
            name: "zonghedetails",
            component: () => import("@/views/ZongHe/ZongHeDetails.vue"),
            meta: { title: "达成度详情", navId: "zonghe-list" },
          },
          {
            path: "ReachDegree",
            name: "ReachDegree",
            component: () =>
              import("@/views/ZongHe/component/reachTable/ReachDegree.vue"),
            meta: { title: "达成度详情", navId: "zonghe-list" },
          },
          {
            path: "SetReach",
            name: "SetReach",
            component: () =>
              import("@/views/ZongHe/component/reachTable/SetReach.vue"),
            meta: { title: "达成度详情", navId: "zonghe-list" },
          },
          {
            path: "studentsList",
            name: "studentsList",
            component: () => import("@/views/ZongHe/studentsList.vue"),
            meta: { title: "达成度详情", navId: "zonghe-list" },
          },
        ],
      },
      {
        path: "gongcheng", // 工程实践项目管理
        name: "GongCheng",
        component: () => import("@/views/GongCheng.vue"),
        meta: {
          navId: "gongcheng",
          requiresAuth: true,
          title: "工程实践项目管理",
        }, // 需要认证
      },
      {
        path: "aiTeaching", // AI教学
        name: "AiTeaching",
        meta: { navId: "aiTeaching", title: "AI教学" },
        children: [
          {
            path: "systemCourseList",
            name: "SystemCourseList",
            component: () => import("@/views/AiTeaching/list_courseSystem.vue"),
            meta: { title: "课程体系列表", navId: "course-system" },
          },
          {
            path: "courseBuildList",
            name: "CourseBuildList",
            component: () => import("@/views/AiTeaching/list_courseBuild.vue"),
            meta: { title: "课程构建列表", navId: "course-build" },
          },
          {
            path: "courseSystem",
            name: "courseSystem",
            component: () => import("@/views/AiTeaching/courseSystem.vue"),
            redirect: "/aiTeaching/systemCourseList",
            meta: { title: "课程体系", navId: "course-system" },
            children: [
              {
                path: "chapterContents",
                name: "ChapterContents",
                component: () =>
                  import("@/views/AiTeaching/system_chapterContents.vue"),
                meta: {
                  title: "章节目录",
                  navId: "course-system",
                  activeMenu: "/aiTeaching/courseSystem/chapterContents",
                },
              },
              {
                path: "courseOutline",
                name: "CourseOutline",
                component: () =>
                  import("@/views/AiTeaching/system_courseOutline.vue"),
                meta: {
                  title: "课程大纲",
                  navId: "course-system",
                  activeMenu: "/aiTeaching/courseSystem/courseOutline",
                },
              },
              {
                path: "aiExam",
                name: "AiExam",
                component: () => import("@/views/AiTeaching/system_aiExam.vue"),
                meta: {
                  title: "智能考核",
                  navId: "course-system",
                  activeMenu: "/aiTeaching/courseSystem/aiExam",
                },
              },
              {
                path: "knowledgeGraph",
                name: "KnowledgeGraph",
                component: () =>
                  import("@/views/AiTeaching/system_knowledgeGraph.vue"),
                meta: {
                  title: "知识图谱",
                  navId: "course-system",
                  activeMenu: "/aiTeaching/courseSystem/knowledgeGraph",
                },
              },
              {
                path: "knowledgeBase",
                name: "KnowledgeBase",
                component: () =>
                  import("@/views/AiTeaching/system_knowledgeBase.vue"),
                meta: {
                  title: "学科知识库",
                  navId: "course-system",
                  activeMenu: "/aiTeaching/courseSystem/knowledgeBase",
                },
              },
              {
                path: "knowledgeBaseDetail",
                name: "KnowledgeBaseDetail",
                component: () =>
                  import("@/views/AiTeaching/system_knowledgeBaseDetail.vue"),
                meta: {
                  title: "学科知识库-详情",
                  navId: "course-system",
                  activeMenu: "/aiTeaching/courseSystem/knowledgeBase",
                },
              },
              {
                path: "aiAnalysis",
                name: "AiAnalysis",
                component: () =>
                  import("@/views/AiTeaching/system_aiAnalysis.vue"),
                meta: {
                  title: "智能分析",
                  navId: "course-system",
                  activeMenu: "/aiTeaching/courseSystem/aiAnalysis",
                },
              },
              {
                path: "aiAnalysisDetail",
                name: "AiAnalysisDetail",
                component: () =>
                  import("@/views/AiTeaching/system_aiAnalysis_detail.vue"),
                meta: {
                  title: "智能分析",
                  navId: "course-system",
                  activeMenu: "/aiTeaching/courseSystem/aiAnalysis",
                },
              },
              {
                path: "teachingManage",
                name: "TeachingManage",
                component: () =>
                  import("@/views/AiTeaching/system_teachingManage.vue"),
                redirect: "/aiTeaching/courseSystem/teachingManage/classManage",
                meta: {
                  title: "教学管理",
                  navId: "course-system",
                  activeMenu: "/aiTeaching/courseSystem/teachingManage",
                },
                children: [
                  {
                    path: "classManage",
                    name: "ClassManage",
                    component: () =>
                      import("@/views/AiTeaching/system_classManage.vue"),
                    meta: {
                      title: "班级管理",
                      navId: "course-system",
                      activeMenu: "/aiTeaching/courseSystem/teachingManage",
                      activeMenu_child:
                        "/aiTeaching/courseSystem/teachingManage/classManage",
                    },
                  },
                  {
                    path: "addClass",
                    name: "AddClass",
                    component: () =>
                      import("@/views/AiTeaching/system_addClass.vue"),
                    meta: {
                      title: "创建班级",
                      navId: "course-system",
                      activeMenu: "/aiTeaching/courseSystem/teachingManage",
                      activeMenu_child:
                        "/aiTeaching/courseSystem/teachingManage/classManage",
                    },
                  },
                  {
                    path: "manageStudent",
                    name: "ManageStudent",
                    component: () =>
                      import("@/views/AiTeaching/system_manageStudent.vue"),
                    meta: {
                      title: "管理学生",
                      navId: "course-system",
                      activeMenu: "/aiTeaching/courseSystem/teachingManage",
                      activeMenu_child:
                        "/aiTeaching/courseSystem/teachingManage/classManage",
                    },
                  },
                  {
                    path: "virtualMachineManage",
                    name: "VirtualMachineManage",
                    component: () =>
                      import(
                        "@/views/AiTeaching/system_virtualMachineManage.vue"
                      ),
                    meta: {
                      title: "虚机管理",
                      navId: "course-system",
                      activeMenu: "/aiTeaching/courseSystem/teachingManage",
                      activeMenu_child:
                        "/aiTeaching/courseSystem/teachingManage/virtualMachineManage",
                    },
                  },
                  {
                    path: "assistantManage",
                    name: "AssistantManage",
                    component: () =>
                      import("@/views/AiTeaching/system_assistantManage.vue"),
                    meta: {
                      title: "助教管理",
                      navId: "course-system",
                      activeMenu: "/aiTeaching/courseSystem/teachingManage",
                      activeMenu_child:
                        "/aiTeaching/courseSystem/teachingManage/assistantManage",
                    },
                  },
                ],
              },
            ],
          },
          {
            path: "courseBuild",
            name: "courseBuild",
            component: () => import("@/views/AiTeaching/courseBuild.vue"),
            redirect: "/aiTeaching/courseBuildList",
            meta: { title: "课程构建", navId: "course-build" },
            children: [
              {
                path: "makeZhinengshibie",
                name: "MakeZhinengshibie",
                component: () =>
                  import("@/views/AiTeaching/make_zhinengshibie.vue"),
                meta: {
                  title: "教材识别",
                  navId: "course-build",
                  activeMenu: "/aiTeaching/courseBuild/makeZhinengshibie",
                },
              },
              {
                path: "makeCourseChapter",
                name: "MakeCourseChapter",
                component: () =>
                  import("@/views/AiTeaching/make_courseChapter.vue"),
                meta: {
                  title: "课程章节",
                  navId: "course-build",
                  activeMenu: "/aiTeaching/courseBuild/makeCourseChapter",
                },
              },
              {
                path: "makeCourseChapterBuild",
                name: "MakeCourseChapterBuild",
                component: () =>
                  import("@/views/AiTeaching/make_courseChapterBuild.vue"),
                meta: {
                  title: "课程章节-智能搭建",
                  navId: "course-build",
                  activeMenu: "/aiTeaching/courseBuild/makeCourseChapter",
                },
              },
              {
                path: "makeCourseChapterBuildQuestion",
                name: "MakeCourseChapterBuildQuestion",
                component: () =>
                  import(
                    "@/views/AiTeaching/make_courseChapterBuild_question.vue"
                  ),
                meta: {
                  title: "课程章节-智能搭建-题库",
                  navId: "course-build",
                  activeMenu: "/aiTeaching/courseBuild/makeCourseChapter",
                },
              },
              {
                path: "makeCourseChapterBuildEditKnowledgeBase",
                name: "MakeCourseChapterBuildEditKnowledgeBase",
                component: () =>
                  import(
                    "@/views/AiTeaching/make_courseChapterBuild_editKnowledgeBase.vue"
                  ),
                meta: {
                  title: "课程章节-智能搭建-编辑知识点",
                  navId: "course-build",
                  activeMenu: "/aiTeaching/courseBuild/makeCourseChapter",
                },
              },
              {
                path: "makeCourseChapterBuildEditshuziren",
                name: "MakeCourseChapterBuildEditshuziren",
                component: () =>
                  import(
                    "@/views/AiTeaching/make_courseChapterBuild_editshuziren.vue"
                  ),
                meta: {
                  title: "课程章节-智能搭建-编辑数字人",
                  navId: "course-build",
                  activeMenu: "/aiTeaching/courseBuild/makeCourseChapter",
                },
              },
              {
                path: "makeKnowledgeBase",
                name: "MakeKnowledgeBase",
                component: () =>
                  import("@/views/AiTeaching/make_knowledgeBase.vue"),
                meta: {
                  title: "学科知识库",
                  navId: "course-build",
                  activeMenu: "/aiTeaching/courseBuild/makeKnowledgeBase",
                },
              },
              {
                path: "makeAddKnowledgeBase",
                name: "MakeAddKnowledgeBase",
                component: () =>
                  import("@/views/AiTeaching/make_addKnowledgeBase.vue"),
                meta: {
                  title: "新增知识库",
                  navId: "course-build",
                  activeMenu: "/aiTeaching/courseBuild/makeKnowledgeBase",
                },
              },
              {
                path: "makeKnowledgeDetail",
                name: "MakeKnowledgeDetail",
                component: () =>
                  import("@/views/AiTeaching/make_knowledgeDetail.vue"),
                meta: {
                  title: "学科知识库-详情",
                  navId: "course-build",
                  activeMenu: "/aiTeaching/courseBuild/makeKnowledgeBase",
                },
              },
              {
                path: "makeKnowledgeGraph",
                name: "MakeKnowledgeGraph",
                component: () =>
                  import("@/views/AiTeaching/make_knowledgeGraph.vue"),
                meta: {
                  title: "知识图谱",
                  navId: "course-build",
                  activeMenu: "/aiTeaching/courseBuild/makeKnowledgeGraph",
                },
              },
              {
                path: "makeUpdateKnowledgeGraph",
                name: "MakeUpdateKnowledgeGraph",
                component: () =>
                  import("@/views/AiTeaching/make_updateKnowledgeGraph.vue"),
                meta: {
                  title: "更新知识图谱",
                  navId: "course-build",
                  activeMenu: "/aiTeaching/courseBuild/makeKnowledgeGraph",
                },
              },
              {
                path: "makeDuomotaiBase",
                name: "MakeDuomotaiBase",
                component: () =>
                  import("@/views/AiTeaching/make_duomotaiBase.vue"),
                meta: {
                  title: "多模态资源库",
                  navId: "course-build",
                  activeMenu: "/aiTeaching/courseBuild/makeDuomotaiBase",
                },
              },
              {
                path: "makeCourseOutline",
                name: "MakeCourseOutline",
                component: () =>
                  import("@/views/AiTeaching/make_courseOutline.vue"),
                meta: {
                  title: "课程大纲",
                  navId: "course-build",
                  activeMenu: "/aiTeaching/courseBuild/makeCourseOutline",
                },
              },
              {
                path: "makeQuestionBank",
                name: "MakeQuestionBank",
                component: () =>
                  import("@/views/AiTeaching/make_questionBank.vue"),
                meta: {
                  title: "课程题库",
                  navId: "course-build",
                  activeMenu: "/aiTeaching/courseBuild/makeQuestionBank",
                },
              },
              // 添加选择题
              {
                path: "makeAddChoiceQuestion",
                name: "MakeAddChoiceQuestion",
                component: () =>
                  import("@/views/AiTeaching/make_addChoiceQuestion.vue"),
                meta: {
                  title: "课程题库",
                  navId: "course-build",
                  activeMenu: "/aiTeaching/courseBuild/makeQuestionBank",
                },
              },
              // 添加判断题
              {
                path: "makeAddJudgeQuestion",
                name: "MakeAddJudgeQuestion",
                component: () =>
                  import("@/views/AiTeaching/make_addJudgeQuestion.vue"),
                meta: {
                  title: "课程题库",
                  navId: "course-build",
                  activeMenu: "/aiTeaching/courseBuild/makeQuestionBank",
                },
              },
              // 添加简答题
              {
                path: "makeAddShortAnswerQuestion",
                name: "MakeAddShortAnswerQuestion",
                component: () =>
                  import("@/views/AiTeaching/make_addShortAnswerQuestion.vue"),
                meta: {
                  title: "课程题库",
                  navId: "course-build",
                  activeMenu: "/aiTeaching/courseBuild/makeQuestionBank",
                },
              },
              // 添加解析题
              {
                path: "makeAddAnalysisQuestion",
                name: "MakeAddAnalysisQuestion",
                component: () =>
                  import("@/views/AiTeaching/make_addAnalysisQuestion.vue"),
                meta: {
                  title: "课程题库",
                  navId: "course-build",
                  activeMenu: "/aiTeaching/courseBuild/makeQuestionBank",
                },
              },
              // 添加填空题
              {
                path: "makeAddFillBlankQuestion",
                name: "MakeAddFillBlankQuestion",
                component: () =>
                  import("@/views/AiTeaching/make_addFillBlankQuestion.vue"),
                meta: {
                  title: "课程题库",
                  navId: "course-build",
                  activeMenu: "/aiTeaching/courseBuild/makeQuestionBank",
                },
              },
              // 导入题库
              {
                path: "makeImportQuestionBank",
                name: "MakeImportQuestionBank",
                component: () =>
                  import("@/views/AiTeaching/make_importQuestionBank.vue"),
                meta: {
                  title: "课程题库",
                  navId: "course-build",
                  activeMenu: "/aiTeaching/courseBuild/makeQuestionBank",
                },
              },
              // excel导入
              {
                path: "makeExcelImport",
                name: "MakeExcelImport",
                component: () =>
                  import("@/views/AiTeaching/make_excelImport.vue"),
                meta: {
                  title: "课程题库",
                  navId: "course-build",
                  activeMenu: "/aiTeaching/courseBuild/makeQuestionBank",
                },
              },
              {
                path: "makeSkills",
                name: "MakeSkills",
                component: () => import("@/views/AiTeaching/make_skills.vue"),
                meta: {
                  title: "技能维度",
                  navId: "course-build",
                  activeMenu: "/aiTeaching/courseBuild/makeSkills",
                },
              },
              {
                path: "makeSkillsTrim",
                name: "MakeSkillsTrim",
                component: () =>
                  import("@/views/AiTeaching/make_skillsTrim.vue"),
                meta: {
                  title: "技能维度-调整维度",
                  navId: "course-build",
                  activeMenu: "/aiTeaching/courseBuild/makeSkills",
                },
              },
              {
                path: "shuzirenTeaching",
                name: "ShuzirenTeaching",
                component: () =>
                  import("@/views/AiTeaching/make_shuzirenTeaching.vue"),
                meta: {
                  title: "数字人讲授",
                  navId: "course-build",
                  activeMenu: "/aiTeaching/courseBuild/shuzirenTeaching",
                },
              },
              {
                path: "addShuzirenVideo",
                name: "AddShuzirenVideo",
                component: () =>
                  import("@/views/AiTeaching/make_addShuzirenVideo.vue"),
                meta: {
                  title: "数字人讲授",
                  navId: "course-build",
                  activeMenu: "/aiTeaching/courseBuild/shuzirenTeaching",
                },
              },
            ],
          },
        ],
      },
      {
        path: "ai", // AI智能分析
        name: "AI",
        component: () => import("@/views/AI.vue"),
        meta: { navId: "ai", requiresAuth: true, title: "AI智能分析" }, // 需要认证
      },
      {
        path: "xueke", // 学科知识库
        name: "XueKe",
        component: () => import("@/views/XueKe.vue"),
        meta: { navId: "xueke", requiresAuth: true, title: "学科知识库" }, // 需要认证
      },
      {
        path: "zhishi", // 知识图谱
        name: "ZhiShi",
        component: () => import("@/views/ZhiShi.vue"),
        meta: { navId: "zhishi", requiresAuth: true, title: "知识图谱" }, // 需要认证
        children: [
          {
            path: "", // 默认子路由
            name: "ZhiShiIndex",
            component: () => import("@/views/zhishi/index.vue"),
          },
          {
            path: "gengxin", // 更新图谱
            name: "ZhiShiGengxin",
            component: () => import("@/views/zhishi/gengxin.vue"),
            meta: { title: "更新图谱" },
          },
        ],
      },
      {
        path: "zhinengti",
        name: "ZhiNengTi",
        component: () => import("@/views/ZhiNengTi.vue"),
        meta: { navId: "zhinengti", requiresAuth: true, title: "AI学伴" }, // 需要认证
        children: [
          {
            path: "", // 默认子路由
            name: "ZhiNengTiIndex",
            component: () => import("@/views/zhinengti/index.vue"),
          },
          {
            path: "zhilist",
            name: "ZhiList",
            component: () => import("@/views/zhinengti/ZhiList.vue"),
            meta: { requiresAuth: true, title: "设置考核智能体" }, // 需要认证
          },
        ],
      },
      {
        path: "agent",
        name: "Agent",
        component: () => import("@/views/Agent.vue"),
        meta: { requiresAuth: true, title: "智能体管理" }, // 需要认证
      },
      {
        path: "shuziren",
        name: "Shuziren",
        component: () => import("@/views/Shuziren.vue"),
        meta: {
          navId: "shuziren",
          requiresAuth: true,
          title: "数字教师资产库",
        }, // 需要认证
      },
      {
        path: "shuziren_make",
        name: "Shuziren_make",
        component: () => import("@/views/Shuziren_make.vue"),
        meta: {
          navId: "shuziren",
          requiresAuth: true,
          title: "数字教师资产库-制作",
        }, // 需要认证
      },
      {
        path: "user",
        name: "User",
        component: () => import("@/views/User.vue"),
        meta: { navId: "user", requiresAuth: true, title: "用户管理" }, // 需要认证
        children: [
          {
            path: "", // 默认子路由
            name: "UserIndex",
            component: () => import("@/views/user/index.vue"),
          },
          {
            path: "studentlist", // 更新图谱
            name: "StudentList",
            component: () => import("@/views/user/StudentList.vue"),
            meta: { title: "学生列表" },
          },
        ],
      },
      {
        path: "dashboard",
        name: "Dashboard",
        component: () => import("@/views/Dashboard.vue"),
        meta: { requiresAuth: true, title: "仪表盘" }, // 需要认证
      },

      // 学生端
      {
        path: "aiStuding",
        name: "AiStuding",
        redirect: "/aiStuding/StuListCourseSystem",
        meta: { requiresAuth: true, title: "AI学伴" },
        children: [
          // 课程列表
          {
            path: "stuListCourseSystem",
            name: "StuListCourseSystem",
            component: () =>
              import("@/views/AiStuding/Stu_listCourseSystem.vue"),
            meta: { title: "课程列表", navId: "aiStuding" },
          },
          {
            path: "stuCourseSystem",
            name: "StuCourseSystem",
            component: () => import("@/views/AiStuding/Stu_courseSystem.vue"),
            redirect: "/aiStuding/stuCourseSystem/stuChapterContents",
            meta: { title: "课程列表", navId: "aiStuding" },
            children: [
              // 章节目录
              {
                path: "stuChapterContents",
                name: "StuChapterContents",
                component: () =>
                  import("@/views/AiStuding/Stu_chapterContents.vue"),
                meta: {
                  title: "章节目录",
                  navId: "aiStuding",
                  activeMenu: "/aiStuding/stuCourseSystem/stuChapterContents",
                },
              },
              // 课程大纲
              {
                path: "stuCourseOutline",
                name: "StuCourseOutline",
                component: () =>
                  import("@/views/AiStuding/Stu_courseOutline.vue"),
                meta: {
                  title: "课程大纲",
                  navId: "aiStuding",
                  activeMenu: "/aiStuding/stuCourseSystem/stuCourseOutline",
                },
              },
              // 智能考核
              {
                path: "stuAiExam",
                name: "StuAiExam",
                component: () => import("@/views/AiStuding/Stu_aiExam.vue"),
                meta: {
                  title: "课程大纲",
                  navId: "aiStuding",
                  activeMenu: "/aiStuding/stuCourseSystem/stuAiExam",
                },
              },
              // 知识图谱
              {
                path: "stuKnowledgeGraph",
                name: "StuKnowledgeGraph",
                component: () =>
                  import("@/views/AiStuding/Stu_knowledgeGraph.vue"),
                meta: {
                  title: "知识图谱",
                  navId: "aiStuding",
                  activeMenu: "/aiStuding/stuCourseSystem/stuKnowledgeGraph",
                },
              },
              // 智能分析
              {
                path: "stuAiAnalysis",
                name: "StuAiAnalysis",
                component: () => import("@/views/AiStuding/Stu_aiAnalysis.vue"),
                meta: {
                  title: "智能分析",
                  navId: "aiStuding",
                  activeMenu: "/aiStuding/stuCourseSystem/stuAiAnalysis",
                },
              },
            ],
          },
        ],
      },
    ],
  },
  {
    path: "/login", // 登录页面
    name: "Login",
    component: () => import("@/views/Login.vue"),
    meta: { title: "登录" },
  },
  {
    path: "/:pathMatch(.*)*", // 捕获所有未定义路径
    name: "NotFound",
    component: () => import("@/views/NotFound.vue"),
    meta: { title: "页面未找到" },
  },
];

// 创建路由实例
const router = createRouter({
  history: createWebHistory(),
  routes,
});

/**
 * 更新文档标题
 * @param {Object} to - 目标路由对象
 */
function updateDocumentTitle(to) {
  const matchedRoutes = to.matched; // 获取当前路由的匹配记录

  // 提取所有匹配路由的标题
  const titles = matchedRoutes
    .filter((route) => route.meta && route.meta.title) // 过滤掉没有 meta.title 的路由
    .map((route) => route.meta.title); // 提取标题

  // 拼接标题链（例如：父标题 - 子标题）
  const fullTitle = titles.join(" - ") || "AI智慧教育平台";

  // 更新文档标题
  document.title = fullTitle;
}

/**
 * 全局前置守卫：检查用户认证状态并控制导航
 */
// router.beforeEach((to, from, next) => {
//   const isAuthenticated = store.state.isAuthenticated; // 获取用户的认证状态
//   //role 1普通教师 2学生 7超级教师
//   const userInfo = JSON.parse(localStorage.getItem("userInfo")) || {};
//   const role = userInfo.role || 0;
//   // 打印调试信息（仅开发环境）
//   if (process.env.NODE_ENV === "development") {
//     console.groupCollapsed(`[Route Guard] Navigating to ${to.path}`);
//     console.log("To:", to);
//     console.log("From:", from);
//     console.log("Authenticated:", isAuthenticated);
//     console.groupEnd();
//   }

//   // 如果目标路由需要认证且用户未登录，则跳转到登录页面
//   // if (to.meta.requiresAuth && !isAuthenticated) {
//   //   console.log("未登录");
//   //   return next({
//   //     path: "/login", // 跳转到登录页面
//   //     query: { redirect: to.fullPath }, // 记录当前路径，以便登录后返回
//   //   });
//   // }

//   // 如果用户已登录但访问登录页面，则跳转到首页
//   // if (to.path === "/login" && isAuthenticated) {
//   //   console.log("已登录");
//   //   return next("/");
//   // }

//   // 如果目标路由不存在，则跳转到首页
//   if (!to.matched.length) {
//     console.warn(`路径 ${to.path} 未匹配到任何路由，跳转到首页`);
//     return next("/");
//   }

//   // 处理根路径跳转
//   if (to.path === "/") {
//     // 明确判断 role 是数字 1、2、7
//     if (role === 1) {
//       return next("/aiTeaching/systemCourseList"); // 普通教师
//     } else if (role === 2) {
//       return next("/gongcheng"); // 学生
//     } else if (role === 7) {
//       return next("/zonghe/zongheping"); // 超级教师
//     } else {
//       // 其他情况（未登录、role 不存在、role 不合法）→ 跳登录
//       return next("/login");
//     }
//   }

//   // 更新文档标题
//   updateDocumentTitle(to);

//   // 正常导航
//   next();
// });

export default router;
